﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Configuration;
using System.Collections;

namespace ASPNETVN.PORTAL.Modules.CMS.Home.Controls
{
    public partial class Style3 : ModulePage
    {
        protected string GetUrl(int itemID)
        {
            Guid tabID = Guid.Empty;
            PortalDataSet ds = PortalConfiguration.GetPortalDataSet();

            foreach (PortalDataSet.TabRow tab in ds.Tab.Rows)
            {
                foreach (PortalDataSet.ModuleRow module in tab.GetModuleRows())
                {
                    if (module.ID == new Guid(this.Settings["CMS.ModuleID"].ToString()))
                    {
                        return string.Format("~/Default.aspx?tabid={0}&mid={1}&itemid={2}&page=detail", tab.ID, module.ID, itemID);
                    }
                }
            }
            return string.Format("~/Default.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                Hashtable settings = this.Settings;
                int recordNumber = Convert.ToInt32(settings["RecordNumber"].ToString());
                Guid moduleID = new Guid(settings["CMS.ModuleID"].ToString());

                IList<Components.Setup> setups = Components.Setup.SelectCollectionAll(moduleID);
                rptCategory.DataSource = Components.Setup.GetCategories(moduleID);
                rptCategory.DataBind();

                foreach (RepeaterItem item in rptCategory.Items)
                {
                    Label lblCategoryID = item.FindControl("lblCategoryID") as Label;
                    Repeater rptItem = item.FindControl("rptItem") as Repeater;
                    if (rptItem != null)
                    {
                        if (lblCategoryID != null)
                        {
                            rptItem.DataSource = Components.Setup.GetItems(moduleID, Convert.ToInt32(lblCategoryID.Text), 2, recordNumber);
                            rptItem.DataBind();
                        }
                    }
                }
            }
        }
    }
}